﻿using CoolEngine.Engine.Scripting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using System.Collections.Generic;
using Microsoft.Scripting.Hosting;
using System;
[assembly:ContainsBoundPythonCommands]
namespace CoolEngineTest
{
    
    
    /// <summary>
    ///This is a test class for ScriptManagerTest and is intended
    ///to contain all ScriptManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    [ContainsBoundPythonCommands]
    public class ScriptManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for RunCommand
        ///</summary>
        [TestMethod()]
        public void RunCommandTest()
        {
            ScriptManager.SearchForBoundFunctions();
            IntWrapper wrapper = new IntWrapper(){ Value=-1};
            ScriptScope scope = ScriptManager.Scope;
            scope.SetVariable("wrapper", wrapper);
            ScriptManager.RunCommand("import clr\nwrapper.Value = 1");
            Assert.AreEqual(1, ((IntWrapper)(scope.GetVariable("wrapper"))).Value);
            
        }
        private class IntWrapper
        {
            public int Value;
        }
        [PythonMethod(Name="func")]
        public static int FUNCFUNCFUNC(int funclol)
        {
            return funclol * 15;
        }
        /// <summary>
        ///A test for SearchForBoundFunctions
        ///</summary>
        [TestMethod()]
        public void SearchForBoundFunctionsTest()
        {
            IEnumerable<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
            ScriptManager.SearchForBoundFunctions(assemblies);

            ScriptManager.RunCommand("myInt = func(2)");
            Assert.AreEqual(30, ScriptManager.Scope.GetVariable("myInt"));
        }
    }
}
